package com.example.zhu95.mytimber.entity

import com.example.zhu95.mytimber.MyApplication
import com.example.zhu95.mytimber.R
import com.example.zhu95.mytimber.utils.Util

/**
 * @author zhu95 on 2017/8/19.
 */

//歌曲信息
data class SongBean(
        /**
         * 歌曲id
         */
        val id: Int,
        /**
         * 歌曲名称
         */
        val title: String,
        /**
         * 歌曲专辑id
         */
        val albumId: Int,
        /**
         * 歌手
         */
        val artistId: Int,
        /**
         * 距离上一次的播放时间
         */
        val bookmark: Long,
        /**
         * 歌曲文件路径
         */
        val path: String,
        /**
         * 播放时长
         */
        val duration: Int,
        /**
         * 歌曲文件大小
         */
        val size: Long,
        /**
         * 录制的年份
         */
        val year: Int,
        /**
         * 添加到内容提供器的时间
         */
        val addTime: Long) {

    val artist: String
        get() {
            val artist = MyApplication.getContext().getString(R.string.unknow)
            for (a in SongData.artists) {
                if (a.id == artistId) {
                    return a.artist
                }
            }
            return artist
        }

    val albumArt: String?
        get() {
            for (a in SongData.albums) {
                if (a.id == albumId) {
                    return a.albumArt
                }
            }
            return null
        }
    val album: String?
        get() {
            for (a in SongData.albums) {
                if (a.id == albumId) {
                    return a.album
                }
            }
            return null
        }

    fun getPlayTime(): String {
        return Util.getPlayTime(duration)
    }

    override fun equals(other: Any?): Boolean {
        if (!(other is SongBean)) {
            return false
        }
        if (this.id == other.id)
            return true
        return false
    }
}
